package com.carbon.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.carbon.domain.Goods;
import com.carbon.domain.Storage;
import com.carbon.dto.WareInDto;
import io.swagger.v3.oas.annotations.Parameters;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.ArrayList;
import java.util.List;

/**
 * 入库信息(Storage)表数据库访问层
 *
 * @author WangFK
 * @since 2023-08-21 13:19:46
 */
@Mapper
public interface StorageMapper extends BaseMapper<Storage> {

    @Select("SELECT\n" +
            "\tt2.id AS id,\n" +
            "\tt2.goods_name goods_name,\n" +
            "\tt2.goods_price,\n" +
            "\tt2.goods_type,\n" +
            "\tt2.goods_img,\n" +
            "\tt2.goods_price,\n" +
            "\tt2.goods_num,\n" +
            "\tt2.goods_type,\n" +
            "\tt2.remark,\n" +
            "\tt1.replenishment_num \n" +
            "FROM\n" +
            "\tstorage_goods t1\n" +
            "\tLEFT JOIN goods t2 ON t1.goods_id = t2.id \n" +
            "\tAND t1.replenishment_num < t2.goods_num \n" +
            "WHERE\n" +
            "\tt1.storage_id = #{id} \n" +
            "\tAND t2.del_flag = '0' \n" +
            "\tAND t2.goods_status = '0'")
    ArrayList<Goods> getGoodListByStorageId(Long id);

    @Select("SELECT\n" +
            "t2.provider_id as providerId,\n" +
            "t2.batch_id as batchId,\n" +
            "t2.ware_id as wareId,\n" +
            "\tt2.goods_name AS goodsName,\n" +
            "\tt2.record_shape AS recordName,\n" +
            "\tt2.record_size AS recordSize,\n" +
            "\tt1.replenishment_num \n" +
            "FROM\n" +
            "\tstorage_goods t1\n" +
            "\tLEFT JOIN goods t2 ON t1.goods_id = t2.id \n" +
            "WHERE\n" +
            "\tt1.storage_id IN \n"+
            "\t<foreach collection='list' index='index' item='item' open='('\n" +
            "\tseparator=',' close=')'>\n" +
            "\t#{ids}\n" +
            "\t</foreach>"
    )
    List<WareInDto> getGoodListByStorageIdList(@Param("ids") List<Long> ids);
    @Select("SELECT\n" +
            "t2.provider_id as providerId,\n" +
            "t2.batch_id as batchId,\n" +
            "t2.ware_id as wareId,\n" +
            "\tt2.goods_name AS goodsName,\n" +
            "\tt2.record_shape AS recordName,\n" +
            "\tt2.record_size AS recordSize,\n" +
            "\tt1.replenishment_num \n" +
            "FROM\n" +
            "\tstorage_goods t1\n" +
            "\tLEFT JOIN goods t2 ON t1.goods_id = t2.id \n" +
            "WHERE\n" +
            "\tt1.storage_id = #{ids}")
    WareInDto getGoodListByStorageIdInfo(Long ids);
}

